/**
 * 
 */
package vanhoc.android.mediakool;

import java.io.File;
import java.io.IOException;

import vanhoc.android.mediakool.R;
import vanhoc.android.mediakool.MediaPlayerService.PlayServiceBinder;
import vanhoc.android.mediakool.MediaPlayerService.SendMessageToActivity;
import vanhoc.android.mediakool.db.DatabaseHelper;

import android.app.Activity;
import android.app.NotificationManager;
import android.app.TabActivity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;
import android.widget.Toast;

/**
 * @author Administrator
 *
 */
public class TabControlActivity extends TabActivity implements OnTabChangeListener {
	//id bai hat dang hat
	int songPlayingID = 0;
	
	//database
	DatabaseHelper db;
	
	LinearLayout tab_footer;
	
	private final String TAB_SONG_TAG 		= "Song";
	private final String TAB_ALBUM_TAG 		= "Album";
	private final String TAB_ARTIST_TAG 	= "Artist";
	private final String TAB_GENRE_TAG 		= "Genre";
	private final String TAB_PLAYLIST_TAG 	= "Playlist";
	private final String TAB_VIDEO_TAG 		= "Video";
	
	/**
	 * Context cua AllSongActivity
	 * Muc dich : la dung context de gui message sang ben AllSongActivity
	 */
	private Context songContext;
	
	/**
	 * chuoi text nhap vao tu o search
	 */
	String txtSearch;
	
	AllSongsActivity songActivity;
	
	/**
	 * 
	 */
	public static final int NOTIFICATION_ID = 10001;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.tab);
		
		//Khi dang choi nhac o min hinh MusicPlayerActivity, user back lai man hinh TabControlActivity se gui qua Intent id cua bai hat dang choi
		//Con khi moi mo ung dung len(tuc la chua choi nha) thi khong co Intent
		//lay ve id cua bai hat dang choi quan intent (neu co)
		this.songPlayingID	=	 getIntent().getExtras().getInt("songPlayingID");
		
		//initTab
		initTabMediaController();
	}
	
	
	
	//init tab
	private void initTabMediaController() {
			Resources res = getResources();
			TabHost tabhost = getTabHost();
			
			//Tab songs
			Intent intentSongs = new Intent(getApplicationContext(), AllSongsActivity.class);
			intentSongs.putExtra("songPlayingID", TabControlActivity.this.songPlayingID);
			TabSpec tabspecSongs = tabhost
										.newTabSpec(TAB_SONG_TAG)
										.setIndicator("Songs", getResources().getDrawable(R.drawable.song_24_icon))
										.setContent(intentSongs);
			
			//Tab albums
			Intent intentAlbums = new Intent(getApplicationContext(), AlbumsActivity.class);
			intentAlbums.putExtra("songPlayingID", TabControlActivity.this.songPlayingID);
			TabSpec tabspecAlbums = tabhost.newTabSpec(TAB_ALBUM_TAG)
										   .setIndicator("Albums", getResources().getDrawable(R.drawable.album_24_icon))
										   .setContent(intentAlbums);
			
			//Tab Artist
			Intent intentArtist = new Intent(getApplicationContext(), ArtistsActivity.class);
			intentArtist.putExtra("songPlayingID", TabControlActivity.this.songPlayingID);
			TabSpec tabspecArtists = tabhost.newTabSpec(TAB_ARTIST_TAG)
										   .setIndicator("Artists", getResources().getDrawable(R.drawable.artist_24_icon))
										   .setContent(intentArtist);
			
			//Tab Genres
			Intent intentGenres = new Intent(getApplicationContext(), GenresActivity.class);
			intentGenres.putExtra("songPlayingID", TabControlActivity.this.songPlayingID);
			TabSpec tabspecGenres = tabhost.newTabSpec(TAB_GENRE_TAG)
										   .setIndicator("Genres", getResources().getDrawable(R.drawable.genres_24_icon))
										   .setContent(intentGenres);
			
			//Tab playlist
			Intent intentPlaylist = new Intent(getApplicationContext(), PlaylistActivity.class);
			intentPlaylist.putExtra("songPlayingID", TabControlActivity.this.songPlayingID);
			TabSpec tabspecPlaylist = tabhost.newTabSpec(TAB_PLAYLIST_TAG)
											 .setIndicator("Playlist", getResources().getDrawable(R.drawable.playlist_24_icon))
											 .setContent(intentPlaylist);
			
			//Tab video
			Intent intentVideo = new Intent(getApplicationContext(), VideosActivity.class);
			TabSpec tabspecVideo = tabhost.newTabSpec(TAB_VIDEO_TAG)
										  .setIndicator("Video", getResources().getDrawable(R.drawable.video_24_icon))
										  .setContent(intentVideo);
			
			
			//Adding all Tabs
			tabhost.addTab(tabspecSongs);
			tabhost.addTab(tabspecAlbums);
			tabhost.addTab(tabspecArtists);
			tabhost.addTab(tabspecGenres);
			tabhost.addTab(tabspecPlaylist);
			tabhost.addTab(tabspecVideo);
			
			
			//set tab dua vao position click ben DashboardActivity
			if (getIntent() != null) {
				//Lay ve vi tri tab da click tu intent DashboardActivity gui qua
				int index = getIntent().getExtras().getInt("tab");
				tabhost.setCurrentTab(index);	
			}else{
				tabhost.setCurrentTab(0);	
			}
			
			
			tabhost.setOnTabChangedListener(this);
	}


	@Override
	public void onTabChanged(String tabId) {
		/*if (tabId.equals(TAB_SONG_TAG)) {
			tab_footer.setVisibility(tab_footer.VISIBLE);
		}else{
			tab_footer.setVisibility(tab_footer.INVISIBLE);
		}*/
	}

	@Override
	public void onBackPressed() {
		Intent it = new Intent(getApplicationContext(), DashboardActivity.class);
    	startActivity(it);
	}
}
